package PAT;

import java.util.Scanner;

public class PAT1046 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int[] values = new int[m+1];
        for (int i = 1; i <= m; i++) {
            values[i] = scanner.nextInt() + values[i-1];
        }
        int n = scanner.nextInt();
        while (n-- > 0) {
            int start = scanner.nextInt();
            int end = scanner.nextInt();
            int abs = Math.abs(values[end-1] - values[start-1]);
            System.out.println(Math.min(abs,values[m]-abs));

        }
    }
}
